﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject.Business;

namespace eProject.Web.UI.Admin
{
    public partial class PlanesManagementAddNew : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                loadData();
            }
        }
        private void loadData() {
            List<Company> company = Company.GetAll();
            ddlCompany.DataSource = company;
            ddlCompany.DataTextField = "Name";
            ddlCompany.DataValueField = "Id";
            ddlCompany.DataBind();
        }
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.btnSubmit.ServerClick += new EventHandler(btnSubmit_Click);
            this.btnReset.ServerClick += new EventHandler(btnReset_Click);
        }
        public void btnReset_Click(object sender, EventArgs e)
        {
            txtPlaneCode.Text = "";
            txtPlaneName.Text = "";
        }
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string planeId = txtPlaneCode.Text.Trim().ToString();
            string planeName = txtPlaneName.Text.Trim().ToString();
            int companyId = int.Parse(ddlCompany.SelectedValue.ToString());
            Planes plane = new Planes();
            plane.PlaneId = planeId;
            plane.PlaneName = planeName;
            plane.CompanyId = companyId;
            plane.Save();
            Response.Redirect("PlanesManagementProgram.aspx");
        }
    }
}